{% extends "layout.html" %}

{% block title %}任务执行记录{% endblock %}

{% block main_content %}
    <!-- MAIN CONTENT -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="page-header">
                    <h1>
                        Job 执行记录
                    </h1>
                </div><!-- /.page-header -->
                <div class="clearfix">
                    <div class="pull-right tableTools-container">

                    </div>
                </div>
                <div class="table-header">

                </div>
                <div>
                    <div class="table-responsive">
                        <table id="job_instance" class="table table-striped table-bordered table-hover">
                        </table>
                    </div>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    {% include "job_instance_json_view.html" %}
    {% include "job_instance_output_view.html" %}
{% endblock %}

{% block script_extend %}
<script type="text/javascript">
        $('[data-rel=tooltip]').tooltip();
        var mData = [
            {
                "mData": "instanceId",
                "bSortable": false,
                "sTitle": "ID"
            }, {
                "mData": "jobName",
                "bSortable": false,
                "sTitle": "任务名称"
            }, {
                "mData": "jobJson",
                "bSortable": false,
                "sTitle": "JobJson",
                "mRender": function (data, type, row) {
                    return '<a class="btn btn-link" data-tb-primary="' + row.instanceId + '" data-ajax-json-view="/job_define/getJobJsonViewer">点击查看</a>';
                }
            }, {
                "mData": "result",
                "bSortable": false,
                "sTitle": "状态",
                "mRender": function (data, type, row) {
                    if (data === 0) {
                        return '<span class="label label-success label-white">成功</span>';
                    } else {
                        return '<span class="label label-danger label-white">失败</span>';
                    }
                }
            }, {
                "mData": "executeOutput",
                "bSortable": false,
                "sTitle": "日志",
                "mRender": function (data, type, row) {
                    return '<a class="btn btn-link" data-tb-primary="' + row.instanceId + '" data-ajax-job-output="/job_define/getJobJsonViewer">点击查看</a>';
                }
            }, {
                "mData": "executeTime",
                "bSortable": false,
                "sTitle": "任务运行时间",
                "defaultContent": "",
                "mRender": function (data, type, row) {
                    return moment(data).format("YYYY-MM-DD HH:mm:ss");
                }
            }, {
                "mData": "endTime",
                "bSortable": false,
                "sTitle": "任务结束时间",
                "defaultContent": "",
                "mRender": function (data, type, row) {
                    return moment(data).format("YYYY-MM-DD HH:mm:ss");
                }
            }];


        /* 绘制table */
        var initTable = function (url) {
            return initDataTable("job_instance", {
                "aoColumns": mData,
                "bDestroy": true,
                "fnDrawCallback": function () {

                }
            }, url, true);
        };

        var dataTable = initTable("/job_instance/list");

        /* 刷新table */
        function reloadTable() {
            dataTable.fnReloadAjax();
        }

         $(document).on('click.modal.api', '[data-ajax-json-view]', function () {
            var $this = $(this);
            var primary = $this.attr("data-tb-primary");
            Action.jsonAsyncActByData("/job_instance/get", {"instanceId": primary}, function (data) {
                if (data.level == 'success' && data.data) {
                    var instance = data.data;

                    $("#json_content").JSONView(instance.jobJson);

                    $("#instance_json_view_modal").modal({
                        keyboard: false,
                        show: true
                    });

                } else {
                    showTopAlert(data.level, data.title, data.msg);
                }
            });

        });

        $(document).on('click.modal.api', '[data-ajax-job-output]', function () {
            var $this = $(this);
            var primary = $this.attr("data-tb-primary");
            Action.jsonAsyncActByData("/job_instance/get", {"instanceId": primary}, function (data) {
                if (data.level == 'success' && data.data) {
                    var instance = data.data;

                    $("#output_content").text(instance.executeOutput);

                    $("#instance_output_modal").modal({
                        keyboard: false,
                        show: true
                    });

                } else {
                    showTopAlert(data.level, data.title, data.msg);
                }
            });

        });
</script>
{% endblock %}